package com.huage.courseplatform.application.service.impl;

import com.huage.courseplatform.application.mapper.BusinessTeacherFlowRecordMapper;
import com.huage.courseplatform.application.mapper.TeacherMapper;
import com.huage.courseplatform.application.model.entity.BusinessTeacherFlowRecord;
import com.huage.courseplatform.application.model.entity.Teacher;
import com.huage.courseplatform.application.model.vo.BusinessTeacherFlowRecordVO;
import com.huage.courseplatform.application.service.TeacherService;
import com.huage.courseplatform.framework.core.impl.BaseServiceImpl;
import com.huage.courseplatform.framework.utils.date.LocalDateTimeUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class TeacherServiceImpl extends BaseServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Resource
    TeacherMapper teacherMapper;

    @Resource
    BusinessTeacherFlowRecordMapper businessTeacherFlowRecordMapper;


    @Override
    @Cacheable(cacheNames="Service:TeacherService:businessId",key = "#businessId",unless="#result == null")
    public List<Teacher> getTeacherByBusinessId(String businessId) {
        return teacherMapper.getTeacherListByBusinessId(businessId);
    }

    @Override
    @Cacheable(cacheNames="Service:TeacherService:userId",key = "#userId",unless="#result == null")
    public Teacher getTeacherByUserId(String userId) {
        return teacherMapper.getTeacherByUserId(userId);
    }


    @Override
    public void applyBusinessBindTeacher(String teacherId, String businessId) {
        BusinessTeacherFlowRecord flowRecord = new BusinessTeacherFlowRecord();
        flowRecord.setTeacherId(teacherId);
        flowRecord.setBusinessId(businessId);
        flowRecord.setSendTime(LocalDateTimeUtil.parse(LocalDateTime.now()));
        businessTeacherFlowRecordMapper.insert(flowRecord);

    }

    @Override
    @Cacheable(cacheNames="Service:BusinessTeacherFlow:teacherId",key = "#id",unless="#result == null")
    public List<BusinessTeacherFlowRecordVO> getTeacherApplyList(String id) {
        return teacherMapper.getTeacherApplyList(id);
    }

}
